package top.codetheory.thread._001_打断;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class _001_TestInterrupt {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            while (true) {
                boolean interrupted = Thread.currentThread().isInterrupted();
                log.info("interrupted: {}", interrupted);
                if (interrupted) {
                    log.info("线程被打断");
                    break;
                }
            }
        }, "t1");
        t1.start();

        Thread.sleep(1000);

        t1.interrupt();

        log.info("main end");

    }
}